﻿using System;
using System.Web.UI;

namespace PortalCurriculo.WebUI.UserControls.Basico
{
    public partial class Button : UserControl
    {
        private static readonly object EventClick = new object();

        [UrlProperty]
        public string ImageUrl { private get; set; }

        public string Text { private get; set; }

        public string ValidationGroup
        {
            set { link.ValidationGroup = value; }
        }

        [UrlProperty]
        public string PostBackUrl { private get; set; }

        protected virtual void OnClick(EventArgs e)
        {
            var onClickHandler = (EventHandler) Events[EventClick];
            if (onClickHandler != null) onClickHandler(link, e);
        }

        public event EventHandler Click
        {
            add
            {
                Events.AddHandler(EventClick, value);
                link.Click += value;
            }
            remove
            {
                Events.RemoveHandler(EventClick, value);
                link.Click -= value;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            image.Src = ImageUrl;
            //image.Visible = ImageUrl != null;
            label.Text = image.Alt = Text;
            //link.PostBackUrl = PostBackUrl;
        }
    }
}